
var queryMoveId;
function showOrderDetails(objInfo) {
    layui.use(['func','layer'], function () {
        let $ = layui.$;
        let moveId = $(objInfo).attr('value');
        queryMoveId = moveId;
        let func = layui.func;
        let layer = layui.layer;
        func.open({
            title: '仓库移货明细管理',
            content: Feng.ctxPath + '/warehouseMove/showOrderDetailIndex?moveId=' + moveId,
            offset: 'auto',
            skin: 'layui-layer-molv',
            success:function (layero) {
                let $iframeDom=$(layero[0]).find(".layui-fluid").eq(0).contents();
                //获取子页面的元素，进行数据渲染
                $iframeDom.find("#parentMoveId").val(moveId);
            }
        });
    })
};

layui.use(['table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;

    /**
     * 仓库移货管理管理
     */
    var WarehouseMove = {
        tableId: "warehouseMoveTable"
    };

    /**
     * 初始化表格的列
     */
    WarehouseMove.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {
                field: 'moveNum', title: '移货单号：自动生成',
                templet: '<div><a href="javascript:void(0);" class="layui-table-link" value="{{d.id}}" onclick="showOrderDetails(this)">{{d.moveNum}}</a></div>',
            },
            {field: 'moveDate', title: '移货日期'},
            {field: 'shopId', title: '分店id'},
            {field: 'moveTotalCount', title: '移货数量'},
            {field: 'moveTotalAmt', title: '移货总金额'},
            {field: 'moveTypeCount', title: '移货项数(种类)'},
            {field: 'moveType', title: '移货类型'},
            {field: 'auditStatus', title: '审核状态'},
            {field: 'moveInWarehouse', title: '移入仓库id'},
            {field: 'moveOutWarehouse', title: '移出仓库id'},
            {field: 'remark', title: '备注'},
            {field: 'handleUser', title: '经手人id'},
            {field: 'createTime', sort: true, title: '创建时间'},
            {field: 'createUser', title: '创建人id'},
            {field: 'auditUser', title: '审核人id'},
            {field: 'auditTime', title: '审核时间'},
            {field: 'updateTime', title: '更新时间'},
            {field: 'printTime', title: '打印时间'},
            {field: 'updateUser', title: '更新人id'},
            {field: 'isDelete', title: '默认为0,1为删除'},
            // {align: 'center', toolbar: '#tableBar', title: '操作'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    WarehouseMove.search = function () {
        var queryData = {};

        queryData['moveNum'] = $('#moveNum').val();
        queryData['moveDate'] = $('#moveDate').val();
        queryData['shopId'] = $('#shopId').val();

        table.reload(WarehouseMove.tableId, {
            where: queryData, page: {curr: 1}
        });
    };

    /**
     * 弹出添加对话框
     */
    WarehouseMove.openAddDlg = function () {
        func.open({
            title: '添加仓库移货管理',
            content: Feng.ctxPath + '/warehouseMove/add',
            tableId: WarehouseMove.tableId,
            offset: 'auto',
            skin: 'layui-layer-molv',
        });
    };

    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    WarehouseMove.openEditDlg = function (data) {
        func.open({
            title: '修改仓库移货管理',
            content: Feng.ctxPath + '/warehouseMove/edit?id=' + data.id,
            tableId: WarehouseMove.tableId
        });
    };


    /**
     * 导出excel按钮
     */
    WarehouseMove.exportExcel = function () {
        var checkRows = table.checkStatus(WarehouseMove.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    WarehouseMove.onDeleteItem = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/warehouseMove/delete", function (data) {
                Feng.success("删除成功!");
                table.reload(WarehouseMove.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + WarehouseMove.tableId,
        url: Feng.ctxPath + '/warehouseMove/list',
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: WarehouseMove.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        WarehouseMove.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {

        WarehouseMove.openAddDlg();

    });

    // 导出excel
    $('#btnExp').click(function () {
        WarehouseMove.exportExcel();
    });

    // 工具条点击事件
    table.on('tool(' + WarehouseMove.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            WarehouseMove.openEditDlg(data);
        } else if (layEvent === 'delete') {
            WarehouseMove.onDeleteItem(data);
        }
    });
});
